package parser

import (
	"learngo/crawler/engine"
	"regexp"
)

const cityRe = `<a href="(http://www.7799520.com/user/[0-9a-z]+.html)"[^>]*>([^<]+)</a>`

func ParseCity(contents []byte) engine.ParseResult {
	re := regexp.MustCompile(cityRe)

	matches := re.FindAllSubmatch(contents, -1)
	result := engine.ParseResult{}
	for _, m := range matches {
		name := string(m[2])
		name = name[1:]
		//result.Items = append(result.Items, "User " + name)
		result.Requests = append(result.Requests, engine.Request{
			Url: string(m[1]),
			//ParserFunc: engine.NilParser,
			ParserFunc: func(c []byte) engine.ParseResult {
					return ParseProfile(c, name)
				},
		})

	}
	return result
}
